package com.manage.dao.impl;

import com.manage.dao.UsersDao;
import com.manage.pojo.Users;
import com.manage.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UsersDaoImpl implements UsersDao {
    @Override
    public Users findOne(String username) throws SQLException {
        QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
        Users query = qr.query("select * from users where username=?", new BeanHandler<Users>(Users.class), username);
        return query;
    }

    @Override
    public int addOne(String username, String password) throws SQLException {
        QueryRunner qr=new QueryRunner();
        int update = qr.update(JDBCUtils.getConn(), "INSERT INTO users(username,PASSWORD) VALUES(?,?)", username, password);
        return update;
    }
}
